package cn.msqweb.util;

import cn.msqweb.model.SecurityUser;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.StringUtils;

import java.util.Set;

public class AuthUtils {
    /**
     * 获取当前用户
     * @return
     */
    public static SecurityUser getSecurityUser(){
        return (SecurityUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    /**
     * 获取当前用户id
     * @return
     */
    public static Long getLoginSecurityUserID(){
        return getSecurityUser().getUserId();
    }

    /**
     * 查询用户操作权限
     * @return
     */
    public static Set<String> getLoginSecurityUserPerms(){
        return getSecurityUser().getPerms();
    }

    /**
     * 获取登录用户的店铺标识
     * @return
     */
    public static Long getLoginShopId() {
        return getSecurityUser().getShopId();
    }

    public static String getLoginMemberOpenId() {
        return getSecurityUser().getOpenId();
    }
}
